<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book Python爬虫课程讲义 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Scrapy框架 | Python爬虫课程讲义</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="BigCat">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-tbfed-pagefooter/footer.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../file/part04/4.1.html" />
    
    
    <link rel="prev" href="../../file/part03/3.9.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="4"
        data-chapter-title="Scrapy框架"
        data-filepath="file/part04/4.md"
        data-basepath="../.."
        data-revision="Thu Feb 09 2017 09:48:59 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        传智播客Python学院爬虫课程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="file/part01/1.html">
            
                
                    <a href="../../file/part01/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        爬虫原理与数据抓取
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="file/part01/1.1.html">
            
                
                    <a href="../../file/part01/1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        (了解)通用爬虫和聚焦爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="file/part01/1.2.html">
            
                
                    <a href="../../file/part01/1.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        (复习)HTTP/HTTPS的请求与响应
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="file/part01/1.3.html">
            
                
                    <a href="../../file/part01/1.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        HTTP/HTTPS抓包工具-Fiddler
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="file/part01/1.4.html">
            
                
                    <a href="../../file/part01/1.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        urllib2模块的基本使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="file/part01/1.5.html">
            
                
                    <a href="../../file/part01/1.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        urllib2：GET请求和POST请求
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="file/part01/1.6.html">
            
                
                    <a href="../../file/part01/1.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        urllib2：Handler处理器和自定义Opener
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="file/part01/1.7.html">
            
                
                    <a href="../../file/part01/1.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        urllib2：URLError与HTTPError
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="file/part01/1.8.html">
            
                
                    <a href="../../file/part01/1.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        Requests模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="file/part02/2.html">
            
                
                    <a href="../../file/part02/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        非结构化数据与结构化数据提取
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="file/part02/2.1.html">
            
                
                    <a href="../../file/part02/2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        正则表达式re模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="file/part02/2.2.html">
            
                
                    <a href="../../file/part02/2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        案例：使用正则表达式的爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="file/part02/2.3.html">
            
                
                    <a href="../../file/part02/2.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        XPath与lxml类库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="file/part02/2.4.html">
            
                
                    <a href="../../file/part02/2.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        案例：使用XPath的爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="file/part02/2.5.html">
            
                
                    <a href="../../file/part02/2.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        BeautifulSoup4 解析器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="file/part02/2.6.html">
            
                
                    <a href="../../file/part02/2.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        案例：使用bs4的爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="file/part02/2.7.html">
            
                
                    <a href="../../file/part02/2.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        JSON模块与JsonPath
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="file/part02/2.8.html">
            
                
                    <a href="../../file/part02/2.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        糗事百科案例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="file/part02/2.9.html">
            
                
                    <a href="../../file/part02/2.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        多线程爬虫案例
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="file/part03/3.html">
            
                
                    <a href="../../file/part03/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        动态HTML处理和机器图像识别
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="file/part03/3.1.html">
            
                
                    <a href="../../file/part03/3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        动态HTML介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="file/part03/3.2.html">
            
                
                    <a href="../../file/part03/3.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Selenium与PhantomJS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="file/part03/3.3.html">
            
                
                    <a href="../../file/part03/3.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        案例一：网站模拟登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="file/part03/3.4.html">
            
                
                    <a href="../../file/part03/3.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        案例二：动态页面模拟点击
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="file/part03/3.5.html">
            
                
                    <a href="../../file/part03/3.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        案例三：执行JavaScript语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="file/part03/3.6.html">
            
                
                    <a href="../../file/part03/3.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        机器视觉与Tesseract介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="file/part03/3.7.html">
            
                
                    <a href="../../file/part03/3.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        处理一些格式规范的文字
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="file/part03/3.8.html">
            
                
                    <a href="../../file/part03/3.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        案例：尝试对验证码进行机器识别处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="file/part03/3.9.html">
            
                
                    <a href="../../file/part03/3.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        机器学习：训练Tesseract
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="4" data-path="file/part04/4.html">
            
                
                    <a href="../../file/part04/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        Scrapy框架
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="file/part04/4.1.html">
            
                
                    <a href="../../file/part04/4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        配置安装
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="file/part04/4.2.html">
            
                
                    <a href="../../file/part04/4.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        入门案例
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="file/part04/4.3.html">
            
                
                    <a href="../../file/part04/4.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        Scrapy Shell
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="file/part04/4.4.html">
            
                
                    <a href="../../file/part04/4.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        Item Pipeline
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="file/part04/4.5.html">
            
                
                    <a href="../../file/part04/4.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        Spiders
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="file/part04/4.6.html">
            
                
                    <a href="../../file/part04/4.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        CrawlSpiders
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="file/part04/4.7.html">
            
                
                    <a href="../../file/part04/4.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        Request/Response
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="file/part04/4.8.html">
            
                
                    <a href="../../file/part04/4.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        Downloader Middlewares
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="file/part04/4.9.html">
            
                
                    <a href="../../file/part04/4.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        Settings
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="file/part05/5.html">
            
                
                    <a href="../../file/part05/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        Scrapy实战项目
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="file/part05/5.1.html">
            
                
                    <a href="../../file/part05/5.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        (案例一)手机App抓包爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="file/part05/5.2.html">
            
                
                    <a href="../../file/part05/5.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        (案例二)阳光热线问政平台爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="file/part05/5.3.html">
            
                
                    <a href="../../file/part05/5.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        (案例三)新浪网分类资讯爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="file/part05/5.4.html">
            
                
                    <a href="../../file/part05/5.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        (案例四)图片下载器爬虫
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="file/part05/5.5.html">
            
                
                    <a href="../../file/part05/5.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        (案例五)将数据保存在MongoDB中
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="file/part05/5.6.html">
            
                
                    <a href="../../file/part05/5.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        (案例六)三种scrapy模拟登陆策略
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="file/part05/5.7.html">
            
                
                    <a href="../../file/part05/5.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        附：通过Fiddler进行手机抓包方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="file/part06/6.html">
            
                
                    <a href="../../file/part06/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        scrapy-redis分布式组件
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="file/part06/6.1.html">
            
                
                    <a href="../../file/part06/6.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        源码分析参考：Connection
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="file/part06/6.2.html">
            
                
                    <a href="../../file/part06/6.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        源码分析参考：Dupefilter
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="file/part06/6.3.html">
            
                
                    <a href="../../file/part06/6.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        源码分析参考：Picklecompat
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="file/part06/6.4.html">
            
                
                    <a href="../../file/part06/6.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        源码分析参考：Pipelines
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="file/part06/6.5.html">
            
                
                    <a href="../../file/part06/6.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        源码分析参考：Queue
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="file/part06/6.6.html">
            
                
                    <a href="../../file/part06/6.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        源码分析参考：Scheduler
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="file/part06/6.7.html">
            
                
                    <a href="../../file/part06/6.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        源码分析参考：Spider
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="file/part07/7.html">
            
                
                    <a href="../../file/part07/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        scrapy-redis实战
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="file/part07/7.1.html">
            
                
                    <a href="../../file/part07/7.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        源码自带项目说明
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="file/part07/7.2.html">
            
                
                    <a href="../../file/part07/7.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        有缘网分布式爬虫项目1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="file/part07/7.3.html">
            
                
                    <a href="../../file/part07/7.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        有缘网分布式爬虫项目2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="file/part07/7.4.html">
            
                
                    <a href="../../file/part07/7.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        处理Redis里的数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="file/part07/7.5.html">
            
                
                    <a href="../../file/part07/7.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        尝试改写新浪网分类资讯爬虫1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="file/part07/7.6.html">
            
                
                    <a href="../../file/part07/7.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        尝试改写新浪网分类资讯爬虫2
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="file/part07/7.7.html">
            
                
                    <a href="../../file/part07/7.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        IT桔子分布式项目1
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.8" data-path="file/part07/7.8.html">
            
                
                    <a href="../../file/part07/7.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.8.</b>
                        
                        IT桔子分布式项目2
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="file/duanzi/duanzi.html">
            
                
                    <a href="../../file/duanzi/duanzi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        课余段子
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Python爬虫课程讲义</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="scrapy-&#x6846;&#x67B6;">Scrapy &#x6846;&#x67B6;</h1>
<ul>
<li><p>Scrapy&#x662F;&#x7528;&#x7EAF;Python&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x4E3A;&#x4E86;&#x722C;&#x53D6;&#x7F51;&#x7AD9;&#x6570;&#x636E;&#x3001;&#x63D0;&#x53D6;&#x7ED3;&#x6784;&#x6027;&#x6570;&#x636E;&#x800C;&#x7F16;&#x5199;&#x7684;&#x5E94;&#x7528;&#x6846;&#x67B6;&#xFF0C;&#x7528;&#x9014;&#x975E;&#x5E38;&#x5E7F;&#x6CDB;&#x3002;</p>
</li>
<li><p>&#x6846;&#x67B6;&#x7684;&#x529B;&#x91CF;&#xFF0C;&#x7528;&#x6237;&#x53EA;&#x9700;&#x8981;&#x5B9A;&#x5236;&#x5F00;&#x53D1;&#x51E0;&#x4E2A;&#x6A21;&#x5757;&#x5C31;&#x53EF;&#x4EE5;&#x8F7B;&#x677E;&#x7684;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x722C;&#x866B;&#xFF0C;&#x7528;&#x6765;&#x6293;&#x53D6;&#x7F51;&#x9875;&#x5185;&#x5BB9;&#x4EE5;&#x53CA;&#x5404;&#x79CD;&#x56FE;&#x7247;&#xFF0C;&#x975E;&#x5E38;&#x4E4B;&#x65B9;&#x4FBF;&#x3002;</p>
</li>
<li><p>Scrapy &#x4F7F;&#x7528;&#x4E86; Twisted<code>[&apos;tw&#x26A;st&#x26A;d]</code>(&#x5176;&#x4E3B;&#x8981;&#x5BF9;&#x624B;&#x662F;Tornado)&#x5F02;&#x6B65;&#x7F51;&#x7EDC;&#x6846;&#x67B6;&#x6765;&#x5904;&#x7406;&#x7F51;&#x7EDC;&#x901A;&#x8BAF;&#xFF0C;&#x53EF;&#x4EE5;&#x52A0;&#x5FEB;&#x6211;&#x4EEC;&#x7684;&#x4E0B;&#x8F7D;&#x901F;&#x5EA6;&#xFF0C;&#x4E0D;&#x7528;&#x81EA;&#x5DF1;&#x53BB;&#x5B9E;&#x73B0;&#x5F02;&#x6B65;&#x6846;&#x67B6;&#xFF0C;&#x5E76;&#x4E14;&#x5305;&#x542B;&#x4E86;&#x5404;&#x79CD;&#x4E2D;&#x95F4;&#x4EF6;&#x63A5;&#x53E3;&#xFF0C;&#x53EF;&#x4EE5;&#x7075;&#x6D3B;&#x7684;&#x5B8C;&#x6210;&#x5404;&#x79CD;&#x9700;&#x6C42;&#x3002;</p>
</li>
</ul>
<h2 id="scrapy&#x67B6;&#x6784;&#x56FE;&#x7EFF;&#x7EBF;&#x662F;&#x6570;&#x636E;&#x6D41;&#x5411;&#xFF1A;">Scrapy&#x67B6;&#x6784;&#x56FE;(&#x7EFF;&#x7EBF;&#x662F;&#x6570;&#x636E;&#x6D41;&#x5411;)&#xFF1A;</h2>
<p><img src="../images/scrapy_all.png" alt=""></p>
<ul>
<li><p><code>Scrapy Engine(&#x5F15;&#x64CE;)</code>: &#x8D1F;&#x8D23;<code>Spider</code>&#x3001;<code>ItemPipeline</code>&#x3001;<code>Downloader</code>&#x3001;<code>Scheduler</code>&#x4E2D;&#x95F4;&#x7684;&#x901A;&#x8BAF;&#xFF0C;&#x4FE1;&#x53F7;&#x3001;&#x6570;&#x636E;&#x4F20;&#x9012;&#x7B49;&#x3002;</p>
</li>
<li><p><code>Scheduler(&#x8C03;&#x5EA6;&#x5668;)</code>: &#x5B83;&#x8D1F;&#x8D23;&#x63A5;&#x53D7;<code>&#x5F15;&#x64CE;</code>&#x53D1;&#x9001;&#x8FC7;&#x6765;&#x7684;Request&#x8BF7;&#x6C42;&#xFF0C;&#x5E76;&#x6309;&#x7167;&#x4E00;&#x5B9A;&#x7684;&#x65B9;&#x5F0F;&#x8FDB;&#x884C;&#x6574;&#x7406;&#x6392;&#x5217;&#xFF0C;&#x5165;&#x961F;&#xFF0C;&#x5F53;<code>&#x5F15;&#x64CE;</code>&#x9700;&#x8981;&#x65F6;&#xFF0C;&#x4EA4;&#x8FD8;&#x7ED9;<code>&#x5F15;&#x64CE;</code>&#x3002;</p>
</li>
<li><p><code>Downloader&#xFF08;&#x4E0B;&#x8F7D;&#x5668;&#xFF09;</code>&#xFF1A;&#x8D1F;&#x8D23;&#x4E0B;&#x8F7D;<code>Scrapy Engine(&#x5F15;&#x64CE;)</code>&#x53D1;&#x9001;&#x7684;&#x6240;&#x6709;Requests&#x8BF7;&#x6C42;&#xFF0C;&#x5E76;&#x5C06;&#x5176;&#x83B7;&#x53D6;&#x5230;&#x7684;Responses&#x4EA4;&#x8FD8;&#x7ED9;<code>Scrapy Engine(&#x5F15;&#x64CE;)</code>&#xFF0C;&#x7531;<code>&#x5F15;&#x64CE;</code>&#x4EA4;&#x7ED9;<code>Spider</code>&#x6765;&#x5904;&#x7406;&#xFF0C;</p>
</li>
<li><p><code>Spider&#xFF08;&#x722C;&#x866B;&#xFF09;</code>&#xFF1A;&#x5B83;&#x8D1F;&#x8D23;&#x5904;&#x7406;&#x6240;&#x6709;Responses,&#x4ECE;&#x4E2D;&#x5206;&#x6790;&#x63D0;&#x53D6;&#x6570;&#x636E;&#xFF0C;&#x83B7;&#x53D6;Item&#x5B57;&#x6BB5;&#x9700;&#x8981;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x5E76;&#x5C06;&#x9700;&#x8981;&#x8DDF;&#x8FDB;&#x7684;URL&#x63D0;&#x4EA4;&#x7ED9;<code>&#x5F15;&#x64CE;</code>&#xFF0C;&#x518D;&#x6B21;&#x8FDB;&#x5165;<code>Scheduler(&#x8C03;&#x5EA6;&#x5668;)</code>&#xFF0C;</p>
</li>
<li><p><code>Item Pipeline(&#x7BA1;&#x9053;)</code>&#xFF1A;&#x5B83;&#x8D1F;&#x8D23;&#x5904;&#x7406;<code>Spider</code>&#x4E2D;&#x83B7;&#x53D6;&#x5230;&#x7684;Item&#xFF0C;&#x5E76;&#x8FDB;&#x884C;&#x8FDB;&#x884C;&#x540E;&#x671F;&#x5904;&#x7406;&#xFF08;&#x8BE6;&#x7EC6;&#x5206;&#x6790;&#x3001;&#x8FC7;&#x6EE4;&#x3001;&#x5B58;&#x50A8;&#x7B49;&#xFF09;&#x7684;&#x5730;&#x65B9;.</p>
</li>
<li><p><code>Downloader Middlewares&#xFF08;&#x4E0B;&#x8F7D;&#x4E2D;&#x95F4;&#x4EF6;&#xFF09;</code>&#xFF1A;&#x4F60;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x662F;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x6269;&#x5C55;&#x4E0B;&#x8F7D;&#x529F;&#x80FD;&#x7684;&#x7EC4;&#x4EF6;&#x3002;</p>
</li>
<li><p><code>Spider Middlewares&#xFF08;Spider&#x4E2D;&#x95F4;&#x4EF6;&#xFF09;</code>&#xFF1A;&#x4F60;&#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x662F;&#x4E00;&#x4E2A;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x6269;&#x5C55;&#x548C;&#x64CD;&#x4F5C;<code>&#x5F15;&#x64CE;</code>&#x548C;<code>Spider</code>&#x4E2D;&#x95F4;<code>&#x901A;&#x4FE1;</code>&#x7684;&#x529F;&#x80FD;&#x7EC4;&#x4EF6;&#xFF08;&#x6BD4;&#x5982;&#x8FDB;&#x5165;<code>Spider</code>&#x7684;Responses;&#x548C;&#x4ECE;<code>Spider</code>&#x51FA;&#x53BB;&#x7684;Requests&#xFF09;</p>
</li>
</ul>
<h2 id="scrapy&#x7684;&#x8FD0;&#x4F5C;&#x6D41;&#x7A0B;">Scrapy&#x7684;&#x8FD0;&#x4F5C;&#x6D41;&#x7A0B;</h2>
<p>&#x4EE3;&#x7801;&#x5199;&#x597D;&#xFF0C;&#x7A0B;&#x5E8F;&#x5F00;&#x59CB;&#x8FD0;&#x884C;...</p>
<ol>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;Hi&#xFF01;<code>Spider</code>, &#x4F60;&#x8981;&#x5904;&#x7406;&#x54EA;&#x4E00;&#x4E2A;&#x7F51;&#x7AD9;&#xFF1F;</p>
</li>
<li><p><code>Spider</code>&#xFF1A;&#x8001;&#x5927;&#x8981;&#x6211;&#x5904;&#x7406;xxxx.com&#x3002;</p>
</li>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;&#x4F60;&#x628A;&#x7B2C;&#x4E00;&#x4E2A;&#x9700;&#x8981;&#x5904;&#x7406;&#x7684;URL&#x7ED9;&#x6211;&#x5427;&#x3002;</p>
</li>
<li><p><code>Spider</code>&#xFF1A;&#x7ED9;&#x4F60;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;URL&#x662F;xxxxxxx.com&#x3002;</p>
</li>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;Hi&#xFF01;<code>&#x8C03;&#x5EA6;&#x5668;</code>&#xFF0C;&#x6211;&#x8FD9;&#x6709;request&#x8BF7;&#x6C42;&#x4F60;&#x5E2E;&#x6211;&#x6392;&#x5E8F;&#x5165;&#x961F;&#x4E00;&#x4E0B;&#x3002;</p>
</li>
<li><p><code>&#x8C03;&#x5EA6;&#x5668;</code>&#xFF1A;&#x597D;&#x7684;&#xFF0C;&#x6B63;&#x5728;&#x5904;&#x7406;&#x4F60;&#x7B49;&#x4E00;&#x4E0B;&#x3002;</p>
</li>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;Hi&#xFF01;<code>&#x8C03;&#x5EA6;&#x5668;</code>&#xFF0C;&#x628A;&#x4F60;&#x5904;&#x7406;&#x597D;&#x7684;request&#x8BF7;&#x6C42;&#x7ED9;&#x6211;&#x3002;</p>
</li>
<li><p><code>&#x8C03;&#x5EA6;&#x5668;</code>&#xFF1A;&#x7ED9;&#x4F60;&#xFF0C;&#x8FD9;&#x662F;&#x6211;&#x5904;&#x7406;&#x597D;&#x7684;request</p>
</li>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;Hi&#xFF01;&#x4E0B;&#x8F7D;&#x5668;&#xFF0C;&#x4F60;&#x6309;&#x7167;&#x8001;&#x5927;&#x7684;<code>&#x4E0B;&#x8F7D;&#x4E2D;&#x95F4;&#x4EF6;</code>&#x7684;&#x8BBE;&#x7F6E;&#x5E2E;&#x6211;&#x4E0B;&#x8F7D;&#x4E00;&#x4E0B;&#x8FD9;&#x4E2A;request&#x8BF7;&#x6C42;</p>
</li>
<li><p><code>&#x4E0B;&#x8F7D;&#x5668;</code>&#xFF1A;&#x597D;&#x7684;&#xFF01;&#x7ED9;&#x4F60;&#xFF0C;&#x8FD9;&#x662F;&#x4E0B;&#x8F7D;&#x597D;&#x7684;&#x4E1C;&#x897F;&#x3002;&#xFF08;&#x5982;&#x679C;&#x5931;&#x8D25;&#xFF1A;sorry&#xFF0C;&#x8FD9;&#x4E2A;request&#x4E0B;&#x8F7D;&#x5931;&#x8D25;&#x4E86;&#x3002;&#x7136;&#x540E;<code>&#x5F15;&#x64CE;</code>&#x544A;&#x8BC9;<code>&#x8C03;&#x5EA6;&#x5668;</code>&#xFF0C;&#x8FD9;&#x4E2A;request&#x4E0B;&#x8F7D;&#x5931;&#x8D25;&#x4E86;&#xFF0C;&#x4F60;&#x8BB0;&#x5F55;&#x4E00;&#x4E0B;&#xFF0C;&#x6211;&#x4EEC;&#x5F85;&#x4F1A;&#x513F;&#x518D;&#x4E0B;&#x8F7D;&#xFF09;</p>
</li>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;Hi&#xFF01;<code>Spider</code>&#xFF0C;&#x8FD9;&#x662F;&#x4E0B;&#x8F7D;&#x597D;&#x7684;&#x4E1C;&#x897F;&#xFF0C;&#x5E76;&#x4E14;&#x5DF2;&#x7ECF;&#x6309;&#x7167;&#x8001;&#x5927;&#x7684;<code>&#x4E0B;&#x8F7D;&#x4E2D;&#x95F4;&#x4EF6;</code>&#x5904;&#x7406;&#x8FC7;&#x4E86;&#xFF0C;&#x4F60;&#x81EA;&#x5DF1;&#x5904;&#x7406;&#x4E00;&#x4E0B;&#xFF08;&#x6CE8;&#x610F;&#xFF01;&#x8FD9;&#x513F;responses&#x9ED8;&#x8BA4;&#x662F;&#x4EA4;&#x7ED9;<code>def parse()</code>&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x5904;&#x7406;&#x7684;&#xFF09;</p>
</li>
<li><p><code>Spider</code>&#xFF1A;&#xFF08;&#x5904;&#x7406;&#x5B8C;&#x6BD5;&#x6570;&#x636E;&#x4E4B;&#x540E;&#x5BF9;&#x4E8E;&#x9700;&#x8981;&#x8DDF;&#x8FDB;&#x7684;URL&#xFF09;&#xFF0C;Hi&#xFF01;<code>&#x5F15;&#x64CE;</code>&#xFF0C;&#x6211;&#x8FD9;&#x91CC;&#x6709;&#x4E24;&#x4E2A;&#x7ED3;&#x679C;&#xFF0C;&#x8FD9;&#x4E2A;&#x662F;&#x6211;&#x9700;&#x8981;&#x8DDF;&#x8FDB;&#x7684;URL&#xFF0C;&#x8FD8;&#x6709;&#x8FD9;&#x4E2A;&#x662F;&#x6211;&#x83B7;&#x53D6;&#x5230;&#x7684;Item&#x6570;&#x636E;&#x3002;</p>
</li>
<li><p><code>&#x5F15;&#x64CE;</code>&#xFF1A;Hi &#xFF01;<code>&#x7BA1;&#x9053;</code> &#x6211;&#x8FD9;&#x513F;&#x6709;&#x4E2A;item&#x4F60;&#x5E2E;&#x6211;&#x5904;&#x7406;&#x4E00;&#x4E0B;&#xFF01;<code>&#x8C03;&#x5EA6;&#x5668;</code>&#xFF01;&#x8FD9;&#x662F;&#x9700;&#x8981;&#x8DDF;&#x8FDB;URL&#x4F60;&#x5E2E;&#x6211;&#x5904;&#x7406;&#x4E0B;&#x3002;&#x7136;&#x540E;&#x4ECE;&#x7B2C;&#x56DB;&#x6B65;&#x5F00;&#x59CB;&#x5FAA;&#x73AF;&#xFF0C;&#x76F4;&#x5230;&#x83B7;&#x53D6;&#x5B8C;&#x8001;&#x5927;&#x9700;&#x8981;&#x5168;&#x90E8;&#x4FE1;&#x606F;&#x3002;</p>
</li>
<li><p><code>&#x7BA1;&#x9053;``&#x8C03;&#x5EA6;&#x5668;</code>&#xFF1A;&#x597D;&#x7684;&#xFF0C;&#x73B0;&#x5728;&#x5C31;&#x505A;&#xFF01;</p>
</li>
</ol>
<p><strong>&#x6CE8;&#x610F;&#xFF01;&#x53EA;&#x6709;&#x5F53;<code>&#x8C03;&#x5EA6;&#x5668;</code>&#x4E2D;&#x4E0D;&#x5B58;&#x5728;&#x4EFB;&#x4F55;request&#x4E86;&#xFF0C;&#x6574;&#x4E2A;&#x7A0B;&#x5E8F;&#x624D;&#x4F1A;&#x505C;&#x6B62;&#xFF0C;&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#xFF0C;&#x5BF9;&#x4E8E;&#x4E0B;&#x8F7D;&#x5931;&#x8D25;&#x7684;URL&#xFF0C;Scrapy&#x4E5F;&#x4F1A;&#x91CD;&#x65B0;&#x4E0B;&#x8F7D;&#x3002;&#xFF09;</strong></p>
<h3 id="&#x5236;&#x4F5C;-scrapy-&#x722C;&#x866B;-&#x4E00;&#x5171;&#x9700;&#x8981;4&#x6B65;&#xFF1A;">&#x5236;&#x4F5C; Scrapy &#x722C;&#x866B; &#x4E00;&#x5171;&#x9700;&#x8981;4&#x6B65;&#xFF1A;</h3>
<ul>
<li>&#x65B0;&#x5EFA;&#x9879;&#x76EE; (scrapy startproject xxx)&#xFF1A;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x722C;&#x866B;&#x9879;&#x76EE;</li>
<li>&#x660E;&#x786E;&#x76EE;&#x6807; &#xFF08;&#x7F16;&#x5199;items.py&#xFF09;&#xFF1A;&#x660E;&#x786E;&#x4F60;&#x60F3;&#x8981;&#x6293;&#x53D6;&#x7684;&#x76EE;&#x6807;</li>
<li>&#x5236;&#x4F5C;&#x722C;&#x866B; &#xFF08;spiders/xxspider.py&#xFF09;&#xFF1A;&#x5236;&#x4F5C;&#x722C;&#x866B;&#x5F00;&#x59CB;&#x722C;&#x53D6;&#x7F51;&#x9875;</li>
<li>&#x5B58;&#x50A8;&#x5185;&#x5BB9; &#xFF08;pipelines.py&#xFF09;&#xFF1A;&#x8BBE;&#x8BA1;&#x7BA1;&#x9053;&#x5B58;&#x50A8;&#x722C;&#x53D6;&#x5185;&#x5BB9;</li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; BigCat all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x300C;Revision Time:
2016-12-08 23:48:29&#x300D;
</span></footer>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../file/part03/3.9.html" class="navigation navigation-prev " aria-label="Previous page: 机器学习：训练Tesseract"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../file/part04/4.1.html" class="navigation navigation-next " aria-label="Next page: 配置安装"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"disqus":{"shortName":"gitbookuse"},"github":{"url":"https://github.com/dododream"},"search-pro":{"cutWordLib":"nodejieba","defineWord":["gitbook-use"]},"sharing":{"weibo":true,"facebook":true,"twitter":true,"google":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"tbfed-pagefooter":{"copyright":"Copyright © BigCat","modify_label":"「Revision Time:","modify_format":"YYYY-MM-DD HH:mm:ss」"},"baidu":{"token":"ff100361cdce95dd4c8fb96b4009f7bc"},"sitemap":{"hostname":"http://www.treenewbee.top"},"donate":{"wechat":"http://weixin.png","alipay":"http://alipay.png","title":"","button":"赏","alipayText":"支付宝打赏","wechatText":"微信打赏"},"edit-link":{"base":"https://github.com/dododream/edit","label":"Edit This Page"},"splitter":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book Python爬虫课程讲义 -->
</html>
